<template>
    <div class="app-container">

        <div class="block">
            <el-row>
                <el-col :span="24">
                    <el-button type="success" icon="el-icon-plus" @click.native="add">{{ $t('button.add') }}</el-button>
                    <el-button type="primary" icon="el-icon-edit" @click.native="edit">{{ $t('button.edit') }}</el-button>
                    <el-button type="danger" icon="el-icon-delete" @click.native="remove">{{ $t('button.delete') }}</el-button>
                </el-col>
            </el-row>
        </div>


        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row
                  @current-change="handleCurrentChange">
            <el-table-column type="expand">
              <template slot-scope="props">
                <el-form label-position="right" inline class="guns-table-expand">
                  <el-form-item label="大楼" >
                    <span>{{ props.row.buildingName }}</span>
                  </el-form-item>
                  <el-form-item label="房间" >
                    <span>{{ props.row.roomName }}</span>
                  </el-form-item>
                  <el-form-item label="位置" >
                    <span>{{ props.row.position }}</span>
                  </el-form-item>
                  <el-form-item label="车位类型" >
                    <span>{{ props.row.parkingTypeName }}</span>
                  </el-form-item>
                </el-form>
              </template>
            </el-table-column>
            <el-table-column label="序号" type="index" show-overflow-tooltip width="50" align="center">
            </el-table-column>
            <el-table-column label="社区" prop="communityName" align="center">
            </el-table-column>
            <el-table-column label="编号" prop="code" align="center">
            </el-table-column>
            <el-table-column label="名称" prop="name" align="center">
            </el-table-column>
            <el-table-column label="租售方式" align="center">
                <template slot-scope="scope">
                  <span style="color:red;" v-if="scope.row.ownerFlag===0">{{scope.row.ownerFlagName}}</span>
                  <span style="color:blue;" v-if="scope.row.ownerFlag===1">{{scope.row.ownerFlagName}}</span>
                  <span style="color:yellowgreen;" v-if="scope.row.ownerFlag===2">{{scope.row.ownerFlagName}}</span>
                </template>
            </el-table-column>
            <el-table-column label="关联客户" prop="custName" align="center">
            </el-table-column>
            <el-table-column label="操作" width="180" align="center">
              <template slot-scope="scope">
                <el-button type="success" icon="el-icon-log" size="mini" @click.native="quoteList(scope.row.communityId, scope.row.id)">报价</el-button>
                <el-button type="success" icon="el-icon-log" size="mini" @click.native="configRule(scope.row.communityId, scope.row.id)">配置</el-button>
              </template>
            </el-table-column>

        </el-table>

        <el-pagination
                background
                layout="total, sizes, prev, pager, next, jumper"
                :page-sizes="[10, 20, 50, 100,500]"
                :page-size="listQuery.limit"
                :total="total"
                @size-change="changeSize"
                @current-change="fetchPage"
                @prev-click="fetchPrev"
                @next-click="fetchNext">
        </el-pagination>

        <el-dialog
                :title="formTitle"
                :visible.sync="formVisible"
                width="70%">
            <el-form ref="form" :model="form" :rules="rules" label-width="150px">
                <el-row>
                    <el-col :span="12">
                      <el-form-item label="社区" prop="communityId">
                        <el-select v-model="form.communityId" placeholder="请选择" @change="getBuildings">
                          <el-option
                            v-for="item in options.communitys"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="大楼" prop="buildingId">
                        <el-select v-model="form.buildingId" placeholder="请选择" @change="getRooms">
                          <el-option
                            v-for="item in options.buildings"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="房间" prop="roomId" >
                          <el-select v-model="form.roomId" placeholder="请选择" >
                            <el-option
                              v-for="item in options.rooms"
                              :key="item.id"
                              :label="item.code"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="编号" prop="code" >
                            <el-input v-model="form.code" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="名称" prop="name" >
                            <el-input v-model="form.name" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="位置" prop="position" >
                            <el-input v-model="form.position" minlength=1></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="车位类型"  prop="parkingType">
                            <el-select v-model="form.parkingType" placeholder="请选择" >
                              <el-option
                                v-for="item in options.parkType"
                                :key="item.k"
                                :label="item.v"
                                :value="item.k">
                              </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                  <el-col :span="12">
                    <el-form-item label="租售方式" prop="ownerFlag" @change="getCusts">
                      <el-select v-model="form.ownerFlag" placeholder="请选择" >
                        <el-option
                          v-for="item in options.parkOwnerFlag"
                          :key="item.k"
                          :label="item.v"
                          :value="item.k">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="save">{{ $t('button.submit') }}</el-button>
                    <el-button @click.native="formVisible = false">{{ $t('button.cancel') }}</el-button>
                </el-form-item>

            </el-form>
        </el-dialog>


        <el-dialog
          :title="quote.quoteTitle"
          :visible.sync="quote.quoteVisible"
          width="70%">
          <el-table :data="quote.list" v-loading="quote.listLoading" element-loading-text="Loading" border fit highlight-current-row>
            <el-table-column label="报价类型" align="center">
              <template slot-scope="scope">
                <span style="color:blue;" v-if="scope.row.quoteType===1">{{scope.row.quoteTypeName}}</span>
                <span style="color:yellowgreen;" v-if="scope.row.quoteType===2">{{scope.row.quoteTypeName}}</span>
              </template>
            </el-table-column>
            <el-table-column label="报价周期" align="center">
              <template slot-scope="scope">
                {{scope.row.quoteRange}} &nbsp;{{scope.row.quoteUnitName}}
              </template>
            </el-table-column>
            <el-table-column label="报价" align="center">
              <template slot-scope="scope">
                {{scope.row.quotePrice}} 元
              </template>
            </el-table-column>
            <el-table-column label="适用规则" align="center">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.check01" :disabled="viewRuleDisabled || scope.row.check02" @change="changeConfig(scope.row)"></el-switch>
              </template>
            </el-table-column>
            <el-table-column label="已选方案" align="center">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.check02" :disabled="true"></el-switch>
              </template>
            </el-table-column>
            <el-table-column label="开始日期" align="center">
              <template slot-scope="scope">
                {{scope.row.startDateStr}}
              </template>
            </el-table-column>
            <el-table-column label="结束日期" align="center">
              <template slot-scope="scope">
                {{scope.row.endDateStr}}
              </template>
            </el-table-column>
          </el-table>
          <div class="block" v-show="viewRuleDisabled1">
            <template>
              <el-button type="primary" @click="saveConfig">{{ $t('button.submit') }}</el-button>
              <el-button @click.native="quote.quoteVisible = false">{{ $t('button.cancel') }}</el-button>
            </template>
          </div>
        </el-dialog>

    </div>
</template>

<script src="./parking_info.js"></script>


<style rel="stylesheet/scss" lang="scss" scoped>
    @import "src/styles/common.scss";
</style>

